home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 3.iso / dist / fw_bc.idb / usr / freeware / info / dc.info.z / dc.info
Text File  |  2001-01-10  |  15KB  |  442 lines

  1. This is dc.info, produced by makeinfo version 4.0 from dc.texi.
  2.  
  3. START-INFO-DIR-ENTRY
  4. * dc: (dc).                   Arbritrary precision RPN "Desktop Calculator".
  5. END-INFO-DIR-ENTRY
  6.    This file documents DC, an arbitrary precision calculator.
  7.  
  8.    Published by the Free Software Foundation, Inc.  59 Temple Place,
  9. Suite 330 Boston, MA 02111 USA
  10.  
  11.    Copyright (C) 1984, 1994, 1997, 1998, 2000 Free Software Foundation,
  12. Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: dc.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  30.  
  31. * Menu:
  32.  
  33. * Introduction::                Introduction
  34. * Invocation::                  Invocation
  35. * Printing Commands::           Printing Commands
  36. * Arithmetic::                  Arithmetic
  37. * Stack Control::               Stack Control
  38. * Registers::                   Registers
  39. * Parameters::                  Parameters
  40. * Strings::                     Strings
  41. * Status Inquiry::              Status Inquiry
  42. * Miscellaneous::               Other commands
  43. * Reporting bugs::              Reporting bugs
  44.  
  45. 
  46. File: dc.info,  Node: Introduction,  Next: Invocation,  Prev: Top,  Up: Top
  47.  
  48. Introduction
  49. ************
  50.  
  51.    DC is a reverse-polish desk calculator which supports unlimited
  52. precision arithmetic.  It also allows you to define and call macros.
  53. Normally DC reads from the standard input; if any command arguments are
  54. given to it, they are filenames, and DC reads and executes the contents
  55. of the files instead of reading from standard input.  All normal output
  56. is to standard output; all error messages are written to standard error.
  57.  
  58.    To exit, use `q'.  `C-c' does not exit; it is used to abort macros
  59. that are looping, etc.  (Currently this is not true; `C-c' does exit.)
  60.  
  61.    A reverse-polish calculator stores numbers on a stack.  Entering a
  62. number pushes it on the stack.  Arithmetic operations pop arguments off
  63. the stack and push the results.
  64.  
  65.    To enter a number in DC, type the digits, with an optional decimal
  66. point.  Exponential notation is not supported.  To enter a negative
  67. number, begin the number with `_'.  `-' cannot be used for this, as it
  68. is a binary operator for subtraction instead.  To enter two numbers in
  69. succession, separate them with spaces or newlines.  These have no
  70. meaning as commands.
  71.  
  72. 
  73. File: dc.info,  Node: Invocation,  Next: Printing Commands,  Prev: Introduction,  Up: Top
  74.  
  75. Invocation
  76. **********
  77.  
  78.    DC may be invoked with the following command-line options:
  79. `-e EXPR'
  80.  
  81. `--expression=EXPR'
  82.      Evaluate EXPR as DC commands.
  83.  
  84. `-f FILE'
  85.  
  86. `--file=FILE'
  87.      Read and evaluate DC commands from FILE.
  88.  
  89. `-h'
  90.  
  91. `--help'
  92.      Print a usage message summarizing the command-line options, then
  93.      exit.
  94.  
  95. `-V'
  96.  
  97. `--version'
  98.      Print the version information for this program, then exit.
  99.  
  100.    If any command-line parameters remain after processing the options,
  101. these parameters are interpreted as additional FILEs whose contents are
  102. read and evaluated.  A file name of `-' refers to the standard input
  103. stream.  If no `-e' option was specified, and no files were specified,
  104. then the standard input will be read for commands to evaluate.
  105.  
  106. 
  107. File: dc.info,  Node: Printing Commands,  Next: Arithmetic,  Prev: Invocation,  Up: Top
  108.  
  109. Printing Commands
  110. *****************
  111.  
  112. `p'
  113.      Prints the value on the top of the stack, without altering the
  114.      stack.  A newline is printed after the value.
  115.  
  116. `n'
  117.      Prints the value on the top of the stack, popping it off, and does
  118.      not print a newline after.  (This command is a GNU extension.)
  119.  
  120. `P'
  121.      Pops off the value on top of the stack.  If it it a string, it is
  122.      simply printed without a trailing newline.  Otherwise it is a
  123.      number, and the integer portion of its absolute value is printed
  124.      out as a "base (UCHAR_MAX+1)" byte stream.  Assuming that
  125.      (UCHAR_MAX+1) is 256 (as it is on most machines with 8-bit bytes),
  126.      the sequence `KSK 0k1/ [_1*]sx d0>x [256~aPd0<x]dsxx sxLKk' could
  127.      also accomplish this function, except for the side-effect of
  128.      clobbering the x register.  (Details of the behavior with a number
  129.      are a GNU extension.)
  130.  
  131. `f'
  132.      Prints the entire contents of the stack without altering anything.
  133.      This is a good command to use if you are lost or want to figure
  134.      out what the effect of some command has been.
  135.  
  136. 
  137. File: dc.info,  Node: Arithmetic,  Next: Stack Control,  Prev: Printing Commands,  Up: Top
  138.  
  139. Arithmetic
  140. **********
  141.  
  142. `+'
  143.      Pops two values off the stack, adds them, and pushes the result.
  144.      The precision of the result is determined only by the values of
  145.      the arguments, and is enough to be exact.
  146.  
  147. `-'
  148.      Pops two values, subtracts the first one popped from the second
  149.      one popped, and pushes the result.
  150.  
  151. `*'
  152.      Pops two values, multiplies them, and pushes the result.  The
  153.      number of fraction digits in the result is the largest of the
  154.      precision value, the number of fraction digits in the multiplier,
  155.      or the number of fraction digits in the multiplicand; but in no
  156.      event exceeding the number of digits required for an exact result.
  157.  
  158. `/'
  159.      Pops two values, divides the second one popped from the first one
  160.      popped, and pushes the result.  The number of fraction digits is
  161.      specified by the precision value.
  162.  
  163. `%'
  164.      Pops two values, computes the remainder of the division that the
  165.      `/' command would do, and pushes that.  The value computed is the
  166.      same as that computed by the sequence `Sd dld/ Ld*-' .
  167.  
  168. `~'
  169.      Pops two values, divides the second one popped from the first one
  170.      popped.  The quotient is pushed first, and the remainder is pushed
  171.      next.  The number of fraction digits used in the division is
  172.      specified by the precision value.  (The sequence `SdSn lnld/
  173.      LnLd%' could also accomplish this function, with slightly
  174.      different error checking.)  (This command is a GNU extension.)
  175.  
  176. `^'
  177.      Pops two values and exponentiates, using the first value popped as
  178.      the exponent and the second popped as the base.  The fraction part
  179.      of the exponent is ignored.  The precision value specifies the
  180.      number of fraction digits in the result.
  181.  
  182. `|'
  183.      Pops three values and computes a modular exponentiation.  The
  184.      first value popped is used as the reduction modulus; this value
  185.      must be a non-zero number, and the result may not be accurate if
  186.      the modulus is not an integer.  The second popped is used as the
  187.      exponent; this value must be a non-negative number, and any
  188.      fractional part of this exponent will be ignored.  The third value
  189.      popped is the base which gets exponentiated, which should be an
  190.      integer.  For small integers this is like the sequence `Sm^Lm%',
  191.      but, unlike `^', this command will work with arbritrarily large
  192.      exponents.  (This command is a GNU extension.)
  193.  
  194. `v'
  195.      Pops one value, computes its square root, and pushes that.  The
  196.      precision value specifies the number of fraction digits in the
  197.      result.
  198.  
  199.    Most arithmetic operations are affected by the _precision value_,
  200. which you can set with the `k' command.  The default precision value is
  201. zero, which means that all arithmetic except for addition and
  202. subtraction produces integer results.
  203.  
  204. 
  205. File: dc.info,  Node: Stack Control,  Next: Registers,  Prev: Arithmetic,  Up: Top
  206.  
  207. Stack Control
  208. *************
  209.  
  210. `c'
  211.      Clears the stack, rendering it empty.
  212.  
  213. `d'
  214.      Duplicates the value on the top of the stack, pushing another copy
  215.      of it.  Thus, `4d*p' computes 4 squared and prints it.
  216.  
  217. `r'
  218.      Reverses the order of (swaps) the top two values on the stack.
  219.      (This command is a GNU extension.)
  220.  
  221. 
  222. File: dc.info,  Node: Registers,  Next: Parameters,  Prev: Stack Control,  Up: Top
  223.  
  224. Registers
  225. *********
  226.  
  227.    DC provides at least 256 memory registers, each named by a single
  228. character.  You can store a number in a register and retrieve it later.
  229.  
  230. `sR'
  231.      Pop the value off the top of the stack and store it into register
  232.      R.
  233.  
  234. `lR'
  235.      Copy the value in register R, and push it onto the stack.  This
  236.      does not alter the contents of R.
  237.  
  238.      Each register also contains its own stack.  The current register
  239.      value is the top of the register's stack.
  240.  
  241. `SR'
  242.      Pop the value off the top of the (main) stack and push it onto the
  243.      stack of register R.  The previous value of the register becomes
  244.      inaccessible.
  245.  
  246. `LR'
  247.      Pop the value off the top of register R's stack and push it onto
  248.      the main stack.  The previous value in register R's stack, if any,
  249.      is now accessible via the `lR' command.
  250.  
  251. 
  252. File: dc.info,  Node: Parameters,  Next: Strings,  Prev: Registers,  Up: Top
  253.  
  254. Parameters
  255. **********
  256.  
  257.    DC has three parameters that control its operation: the precision,
  258. the input radix, and the output radix.  The precision specifies the
  259. number of fraction digits to keep in the result of most arithmetic
  260. operations.  The input radix controls the interpretation of numbers
  261. typed in; _all_ numbers typed in use this radix.  The output radix is
  262. used for printing numbers.
  263.  
  264.    The input and output radices are separate parameters; you can make
  265. them unequal, which can be useful or confusing.  The input radix must
  266. be between 2 and 16 inclusive.  The output radix must be at least 2.
  267. The precision must be zero or greater.  The precision is always
  268. measured in decimal digits, regardless of the current input or output
  269. radix.
  270.  
  271. `i'
  272.      Pops the value off the top of the stack and uses it to set the
  273.      input radix.
  274.  
  275. `o'
  276.      Pops the value off the top of the stack and uses it to set the
  277.      output radix.
  278.  
  279. `k'
  280.      Pops the value off the top of the stack and uses it to set the
  281.      precision.
  282.  
  283. `I'
  284.      Pushes the current input radix on the stack.
  285.  
  286. `O'
  287.      Pushes the current output radix on the stack.
  288.  
  289. `K'
  290.      Pushes the current precision on the stack.
  291.  
  292. 
  293. File: dc.info,  Node: Strings,  Next: Status Inquiry,  Prev: Parameters,  Up: Top
  294.  
  295. Strings
  296. *******
  297.  
  298.    DC can operate on strings as well as on numbers.  The only things
  299. you can do with strings are print them and execute them as macros
  300. (which means that the contents of the string are processed as DC
  301. commands).  Both registers and the stack can hold strings, and DC
  302. always knows whether any given object is a string or a number.  Some
  303. commands such as arithmetic operations demand numbers as arguments and
  304. print errors if given strings.  Other commands can accept either a
  305. number or a string; for example, the `p' command can accept either and
  306. prints the object according to its type.
  307.  
  308. `[CHARACTERS]'
  309.      Makes a string containing CHARACTERS and pushes it on the stack.
  310.      For example, `[foo]P' prints the characters `foo' (with no
  311.      newline).
  312.  
  313. `a'
  314.      The mnemonic for this is somewhat erroneous: asciify.  The
  315.      top-of-stack is popped.  If it was a number, then the low-order
  316.      byte of this number is converted into a string and pushed onto the
  317.      stack.  Otherwise the top-of-stack was a string, and the first
  318.      character of that string is pushed back.  (This command is a GNU
  319.      extension.)
  320.  
  321. `x'
  322.      Pops a value off the stack and executes it as a macro.  Normally
  323.      it should be a string; if it is a number, it is simply pushed back
  324.      onto the stack.  For example, `[1p]x' executes the macro `1p',
  325.      which pushes 1 on the stack and prints `1' on a separate line.
  326.  
  327.      Macros are most often stored in registers; `[1p]sa' stores a macro
  328.      to print `1' into register `a', and `lax' invokes the macro.
  329.  
  330. `>R'
  331.      Pops two values off the stack and compares them assuming they are
  332.      numbers, executing the contents of register R as a macro if the
  333.      original top-of-stack is greater.  Thus, `1 2>a' will invoke
  334.      register `a''s contents and `2 1>a' will not.
  335.  
  336. `!>R'
  337.      Similar but invokes the macro if the original top-of-stack is not
  338.      greater (is less than or equal to) what was the second-to-top.
  339.  
  340. `<R'
  341.      Similar but invokes the macro if the original top-of-stack is less.
  342.  
  343. `!<R'
  344.      Similar but invokes the macro if the original top-of-stack is not
  345.      less (is greater than or equal to) what was the second-to-top.
  346.  
  347. `=R'
  348.      Similar but invokes the macro if the two numbers popped are equal.
  349.  
  350. `!=R'
  351.      Similar but invokes the macro if the two numbers popped are not
  352.      equal.
  353.  
  354. `?'
  355.      Reads a line from the terminal and executes it.  This command
  356.      allows a macro to request input from the user.
  357.  
  358. `q'
  359.      During the execution of a macro, this command exits from the macro
  360.      and also from the macro which invoked it.  If called from the top
  361.      level, or from a macro which was called directly from the top
  362.      level, the `q' command will cause DC to exit.
  363.  
  364. `Q'
  365.      Pops a value off the stack and uses it as a count of levels of
  366.      macro execution to be exited.  Thus, `3Q' exits three levels.
  367.  
  368. 
  369. File: dc.info,  Node: Status Inquiry,  Next: Miscellaneous,  Prev: Strings,  Up: Top
  370.  
  371. Status Inquiry
  372. **************
  373.  
  374. `Z'
  375.      Pops a value off the stack, calculates the number of digits it has
  376.      (or number of characters, if it is a string) and pushes that
  377.      number.
  378.  
  379. `X'
  380.      Pops a value off the stack, calculates the number of fraction
  381.      digits it has, and pushes that number.  For a string, the value
  382.      pushed is 0.
  383.  
  384. `z'
  385.      Pushes the current stack depth: the number of objects on the stack
  386.      before the execution of the `z' command.
  387.  
  388. 
  389. File: dc.info,  Node: Miscellaneous,  Next: Reporting bugs,  Prev: Status Inquiry,  Up: Top
  390.  
  391. Miscellaneous
  392. *************
  393.  
  394. `!'
  395.      Will run the rest of the line as a system command.  Note that
  396.      parsing of the !<, !=, and !> commands take precidence, so if you
  397.      want to run a command starting with <, =, or > you will need to
  398.      add a space after the !.
  399.  
  400. `#'
  401.      Will interpret the rest of the line as a comment.  (This command
  402.      is a GNU extension.)
  403.  
  404. `:R'
  405.      Will pop the top two values off of the stack.  The old
  406.      second-to-top value will be stored in the array R, indexed by the
  407.      old top-of-stack value.
  408.  
  409. `;R'
  410.      Pops the top-of-stack and uses it as an index into the array R.
  411.      The selected value is then pushed onto the stack.
  412.  
  413.    Note that each stacked instance of a register has its own array
  414. associated with it.  Thus `1 0:A 0SA 2 0:A LA 0;Ap' will print 1,
  415. because the 2 was stored in an instance of 0:A that was later popped.
  416.  
  417. 
  418. File: dc.info,  Node: Reporting bugs,  Prev: Miscellaneous,  Up: Top
  419.  
  420. Reporting bugs
  421. **************
  422.  
  423.    Email bug reports to <bug-dc@gnu.org>.
  424.  
  425.  
  426. 
  427. Tag Table:
  428. Node: Top1084
  429. Node: Introduction1663
  430. Node: Invocation2880
  431. Node: Printing Commands3724
  432. Node: Arithmetic4902
  433. Node: Stack Control7815
  434. Node: Registers8228
  435. Node: Parameters9154
  436. Node: Strings10415
  437. Node: Status Inquiry13385
  438. Node: Miscellaneous13942
  439. Node: Reporting bugs14909
  440. 
  441. End Tag Table
  442.